package ar.com.temporis.ui.login;

import ar.com.temporis.system.domain.User;
import ar.com.temporis.system.persistence.UserRepository;


/**
 * 
 * @author matias
 * 
 */
public class LoginWindow extends AbstractWindow {
	
	private String username;
	private String password;
	
	private UserRepository userRepository;
	
	public LoginWindow() {
		this.userRepository = (UserRepository) applicationContext.getBean("userRepository");
	}

	public void setUserRepository(UserRepository userRepository) {
		this.userRepository = userRepository;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public void login() {
		User user = this.userRepository.findUserBy(username, password);
		
		this.getRoot().getDesktop().setAttribute(User.USER, user);
		
		this.getRoot().getDesktop().getExecution().sendRedirect("/home.zul");
	}

}
